package io.renren.modules.hospital.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.renren.modules.hospital.entity.EmrYsInfoEntity;
import io.renren.modules.hospital.service.EmrYsInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author starry
 * @email 2495646304@qq.com
 * @date 2024-01-29 18:00:42
 */
@RestController
@RequestMapping("hospital/emrysinfo")
@Api(value = "EMR医生接口", tags = "EMR医生接口")
public class EmrYsInfoController {
    @Autowired
    private EmrYsInfoService emrYsInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("列表")
    //@RequiresPermissions("hospital:emrysinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = emrYsInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{emrYsId}")
    @ApiOperation("信息")
    //@RequiresPermissions("hospital:emrysinfo:info")
    public R info(@PathVariable("emrYsId") Integer emrYsId) {
        EmrYsInfoEntity emrYsInfo = emrYsInfoService.getById(emrYsId);

        return R.ok().put("emrYsInfo", emrYsInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存")
    //@RequiresPermissions("hospital:emrysinfo:save")
    public R save(@RequestBody EmrYsInfoEntity emrYsInfo) {
        emrYsInfoService.save(emrYsInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改")
    //@RequiresPermissions("hospital:emrysinfo:update")
    public R update(@RequestBody EmrYsInfoEntity emrYsInfo) {
        emrYsInfoService.updateById(emrYsInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除")
    //@RequiresPermissions("hospital:emrysinfo:delete")
    public R delete(@RequestBody Integer[] emrYsIds) {
        emrYsInfoService.removeByIds(Arrays.asList(emrYsIds));

        return R.ok();
    }

    /**
     * 根据科室名称查找该科室下的所有医生
     *
     * @return 医生列表
     */

    @GetMapping("/getYsListBySection")
    @ApiOperation("根据科室名称查找该科室下的所有医生")
    public R getYsListBySection(String ysSection) {
        List<EmrYsInfoEntity> ysInfoEntities = emrYsInfoService.getYsListBySection(ysSection);
        return R.ok().put("ysList", ysInfoEntities);
    }


    @RequestMapping(value = "/info_param", method = RequestMethod.GET)
    // @RequiresPermissions("generator:bbs:info")
    @ApiOperation("查找用户(不同参数)")
    public R getInfoWithParam(@RequestParam("key") String key, @RequestParam("paramType") String paramType, @RequestParam("page") int page, @RequestParam("limit") int limit){
        List<EmrYsInfoEntity> list = emrYsInfoService.getBbsListByParam(key, paramType, page, limit);
        System.out.println(list);
        PageUtils res = new PageUtils(list,list.size(), limit, page);
        return R.ok().put("page", res);
    }

}
